
<%@ include file="/common/taglibs.jsp"%>
<!--分页查询共用的页面-->
<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript" src="<%=jsPath%>/jquery/jquery.timers.js"></script><!--定时器-->
<script type="text/javascript" src="<%=jsPath%>/terminalCommand.js"></script><!--终端命令结果查询-->
<script type="text/javascript" src="<%=jsPath%>/videoPlayer.js"></script><!--终端命令结果查询-->

<style>

	.text_fl
	{
		float:left;
		padding:5px;
		text-align:right;
		width:130px;
	}

	.num_box
	{
		width:10px;
		padding:5px;
		border-color:blue;
		border:1px;
		float:left;
	}

	.clearfix {
		content:"";
		display: block;
		clear:both;
	}

</style>

<script>

	function  startListen() {
	    var vehicleId = ${vehicleId};
	    var simNo = "${simNo}";
	    var channel = 1;
        var ret = window.parent.MyVideoPlayer.startListen(vehicleId, simNo, channel);
        if (ret == 0) {
            //$("input[name='listing']").attr("disabled", true);
            this.isListening = true;
            //$("#listenTip").html(lang.requiring);
            //$("#btnListen").html(lang.stop);
        } else if(ret == -1) {//视频插件未开启
            //$.dialog.tips(parent.lang.vedio_undefined, 1);
			alert("lisetn error");
        }else{
            //一般都不会到此接口
            //除非视频插件没有初始化完成
        }
    }

    function onStopListen()
	{
        var vehicleId = ${vehicleId};
        var simNo = "${simNo}";
        var channel = 1;
        var ret = window.parent.MyVideoPlayer.stopListen(simNo);
        if (ret == 0) {
            //$("input[name='listing']").attr("disabled", true);
            //this.isListening = true;
            //$("#listenTip").html(lang.requiring);
            //$("#btnListen").html(lang.stop);
        } else if(ret == -1) {//视频插件未开启
            //$.dialog.tips(parent.lang.vedio_undefined, 1);
            alert("lisetn error");
        }else{
            //一般都不会到此接口
            //除非视频插件没有初始化完成
        }
	}

    function stopListen()
	{
	    var vehicleId = ${vehicleId};
        var simNo = "${simNo}";
        var channel = 1;
	    var url = "<%=ApplicationPath%>/videoCommand/stopListen.action";
	    var param = {vehicleId:vehicleId, simNo:simNo,channelId:channel};
	    $.getJSON(url, param, function(result)
		{
		    var message = result.success ? "停止成功": "停止失败";
		    $(".commandMsg").html(message);
		    if(result.success)
			{
                var commandId = result.data; //下发成功后，获取到命令Id
                TerminalCommand.startQueryResult(commandId,null,onStopListen);//命令下发成功,根据命令id,开始尝试获取检索结果
			}

		})
	}

    function onCommandSuccess()
	{
	    startListen();
	}

	function adjust()
	{
	    var brightness = $("#input_brightness").val();
	    var color = $("#input_color").val();
	    var contrast = $("#input_contrast").val();
	    var saturation = $("#input_saturation").val();
        window.parent.MyVideoPlayer.getVideoHandler().setVideoColor(brightness,color,contrast, saturation);
	}

    function getSliderValue(realValue)
    {
        return (realValue + 255) * 100 / (255 + 255);
    }

    //滑块方法封装
    function sliderfun(s1,s2,s3,minValue, maxValue,defaultValue){
        var sliderLength = 130;//滑块长度
        $(s3).empty().val(defaultValue);
        defaultValue = getSliderValue(defaultValue);
        $(s2).slider({
            mode: 'h',
            value : defaultValue,
            onChange:function(newValue,oldValue){
                $(s2).width(newValue*sliderLength/100);
                var result = minValue + newValue*(maxValue - minValue)/100;
                $(s3).val(result);
                adjust();
            }
        });

        $(s1).width(defaultValue*sliderLength/100);

        $(s3).on('keyup',function(){
            var val = $(this).val();
            if(val==''||val==null||val==undefined||isNaN(val)){
                val=0;
            }
            var num = parseInt(val);
            $(this).empty().val(num);

            var width = num*sliderLength/100;
            $(s2).slider('setValue', getSliderValue(num));
            $(s1).css('width', width);
            adjust();
        });
    }


    function  setDefault() {
        $("#slider_brightness").slider('setValue', getSliderValue(0));
        $("#slider_color").slider('setValue', getSliderValue(0));
        $("#slider_contrast").slider('setValue', getSliderValue(127));
        $("#slider_saturation").slider('setValue', getSliderValue(1));
        adjust();
    }





$().ready(function() {
	 $("#entityForm").validate(); //初始化验证信息

	$("#btnAdjust").click(function()
	{
	    setDefault();
	});

    /*亮度滑块*/
    sliderfun(".ssa","#slider_brightness","#input_brightness",-255,255,0);
    sliderfun(".ssa","#slider_color","#input_color",-255,255,0);
    sliderfun(".ssa","#slider_contrast","#input_contrast",-255,255,127);
    sliderfun(".ssa","#slider_saturation","#input_saturation",-255,255,1);
});
</script>
 <BODY>
	<form id="entityForm" name="entityForm" 
			action='<%=ApplicationPath%>/videoCommand/listen.action' method="POST">
				
        <input type="hidden"  name="vehicleId"  id="vehicleId" value="${vehicleId}"/>
		<input type="hidden"  name="simNo"  id="simNo" value="${simNo}"/>
  <table width="100%"  class="TableBlock">
					<tbody><tr>
						<td colspan="2" style="font-weight: bold; background: #EFEFEF;" height="25">监听信息
						<span style="color:red;background:blue;">${message}</span>
						</td>
					</tr>

					<tr>
						<td align="center" colspan="2">

							<div style="width:100%">
								<div class="text_fl" >亮度设置:</div>
								<div class="logo-1 fl"></div>
								<div class="text_fl " style="width:250px">
									<div class="swip_box" >
										<div id="slider_brightness"></div>
										<div class="ssa"></div>
									</div>
								</div>
								<div class="num_box " >
									<div class="box1 ">
										<input id="input_brightness" class="fl" type="text" value="" size="1" />

									</div>
								</div>
							</div>
							<div class="clearfix">

								<div class=" text_fl" >  色度设置:</div>
								<div class="logo-1 fl"></div>
								<div class="text_fl " style="width:250px">
									<div class="swip_box" >
										<div id="slider_color"></div>
										<div class="ssa"></div>
									</div>
								</div>
								<div class="num_box " >
									<div class="box1">
										<input id="input_color" class="fl" type="text" value="" size="1" />

									</div>
								</div>

							</div>

							<div class="clearfix">

								<div class=" text_fl" >对比度设置:</div>
								<div class="logo-1 fl"></div>
								<div class="text_fl " style="width:250px">
									<div class="swip_box" >
										<div id="slider_contrast"></div>
										<div class="ssa"></div>
									</div>
								</div>
								<div class="num_box " >
									<div class="box1">
										<input id="input_contrast" class="fl" type="text" value="" size="1" />

									</div>
								</div>

							</div>
							<div class="clearfix">

								<div class=" text_fl" >饱和度设置:</div>
								<div class="logo-1 fl"></div>
								<div class="text_fl " style="width:250px">
									<div class="swip_box" >
										<div id="slider_saturation"></div>
										<div class="ssa"></div>
									</div>
								</div>
								<div class="num_box " >
									<div class="box1">
										<input id="input_saturation" class="fl" type="text" value="" size="1" />

									</div>
								</div>

							</div>
						</td>
					</tr>
					<tr>


						<td colspan=2 align="center">
						   <input id="btnAdjust" type="button" class="sendjson" value="恢复默认">
						   <span class="commandMsg"></span></td>
						
					</tr>

				
					
				</tbody></table>


 </BODY>
</HTML>
